<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单列表')"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: s2ztree-css" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>归属码商：</label>
                            <!--                                <select name="recipientUid" id="recipientUid" class="form-control"-->
                            <!--                                        th:with="type=${@sysUser.selectUserListByType('ms')}">-->
                            <!--                                    <option value="">所有</option>-->
                            <!--                                    <option th:each="dict : ${type}" th:text="${dict.userName}"-->
                            <!--                                            th:value="${dict.userId}"></option>-->
                            <!--                                </select>-->
                            <select  name="recipientUid" id="recipientUid" class="form-control"></select>

                        </li>
                        <li>
                            <label>时间类型：</label>
                            <select name="timeType" id="timeType" class="form-control">
                                <option value="create">创建时间</option>
                                <option value="notify">回调时间</option>
                            </select>
                        </li>
                        <li>
                            <p>开始时间：</p>
                            <!-- th:value="${#dates.format(new java.util.Date(), 'yyyy-MM-dd')}"-->
                            <!--                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"-->
                            <!--                                   th:value="${#dates.format(new java.util.Date(), 'yyyy-MM-dd HH:mm:ss')}"-->
                            <!--                                   data-type="datetime"-->
                            <!--                                   data-format="yyyy-MM-dd HH:mm:ss"-->
                            <!--                                   name="params[beginCreateTime]"/>-->
                            <input type="text" class="form-control" id="startTime"  name="params[beginCreateTime]"
                                   th:value="${#dates.format(new java.util.Date(), 'yyyy-MM-dd 00:00:00')}"
                                   placeholder="yyyy-MM-dd HH:mm:ss">

                            <!--                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"-->
                            <!--                                   th:value="${#dates.format(new java.util.Date(), 'yyyy-MM-dd HH:mm:ss')}"-->
                            <!--                                   data-type="datetime"-->
                            <!--                                   data-format="yyyy-MM-dd HH:mm:ss"-->
                            <!--                                   name="params[endCreateTime]"/>-->
                        </li>
                        <li>
                            <p>结束时间：</p>
                            <!-- th:value="${#dates.format(new java.util.Date(), 'yyyy-MM-dd')}"-->
                            <!--                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"-->
                            <!--                                   th:value="${#dates.format(new java.util.Date(), 'yyyy-MM-dd HH:mm:ss')}"-->
                            <!--                                   data-type="datetime"-->
                            <!--                                   data-format="yyyy-MM-dd HH:mm:ss"-->
                            <!--                                   name="params[beginCreateTime]"/>-->

                            <input type="text" class="form-control" id="endTime"  name="params[endCreateTime]"
                                   th:value="${#dates.format(new java.util.Date(), 'yyyy-MM-dd 23:59:59')}"
                                   placeholder="yyyy-MM-dd HH:mm:ss">
                            <!--                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"-->
                            <!--                                   th:value="${#dates.format(new java.util.Date(), 'yyyy-MM-dd HH:mm:ss')}"-->
                            <!--                                   data-type="datetime"-->
                            <!--                                   data-format="yyyy-MM-dd HH:mm:ss"-->
                            <!--                                   name="params[endCreateTime]"/>-->
                        </li>
                        <li>
                            <label>通道类型：</label>
                            <select name="channelType" id="channelType"  class="form-control" th:with="type=${@dict.getType('channel_type')}" onchange="changeType()">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>通道编码：</label>
                            <select name="channel" id="channel"  class="form-control" >
                                <option value="">所有</option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">

            <a class="btn btn-warning" onclick="$.table.exportExcel()"
               shiro:hasPermission="clearing:clearingOrder:export">
                <i class="fa fa-download"></i> 导出
            </a>


        </div>
        <div class="col-sm-12 select-table table-striped table-responsive">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: s2ztree-js" />

<script th:inline="javascript">


    var prefix = ctx + "business/orderInfo";
    var userTreeurl = ctx + "system/user/userTreeData" ;

    var setting = {
        view : {
            dblClickExpand : false,
            expandAll: true  // 设置默认展开所有节点
        },
        data : {
            simpleData : {
                enable : true
            }
        }
    };
    $(function () {

        layui.use('laydate', function(){
            var laydate = layui.laydate;
            laydate.render({
                elem: '#startTime',
                type: 'datetime',
                trigger: 'click'
            });
            laydate.render({
                elem: '#endTime',
                type: 'datetime',
                trigger: 'click'
            });
        });
        getUserSelectTree();

        var options = {
            classes: "table text-nowrap",
            url: prefix + "/msStatistic",
            exportUrl: prefix + "/statisticsExport",
            modalName: "各通道分润统计",
            showFooter:true,
            columns: [
                {
                    field: 'userId',
                    title: '商户编码',
                },
                {
                    field: 'userName',
                    title: '码商名称',
                },
                {
                    field: 'channelType',
                    title: '通道类型'
                },
                {
                    field: 'channel',
                    title: '通道编码'
                },
                {
                    field: 'channelDesc',
                    title: '通道名称'
                },
                {
                    field: 'totalReceiptMoney',
                    title: '成功金额',
                    footerFormatter: function (value) {
                        var count = 0;
                        for (var i in value) {
                            count += parseFloat(value[i].totalReceiptMoney);
                        }
                        return count.toFixed(4)+"元";
                    },
                    formatter: function (value, row, index) {
                        return  (row.totalReceiptMoney == null ? 0 : parseFloat(row.totalReceiptMoney)) + '元'
                    }
                },
                {
                    field: 'totalMoney',
                    title: '总金额',
                    footerFormatter: function (value) {
                        var count = 0;
                        for (var i in value) {
                            count += parseFloat(value[i].totalMoney);
                        }
                        return count.toFixed(4)+"元";
                    },
                    formatter: function (value, row, index) {
                        return  (row.totalMoney == null ? 0 : parseFloat(row.totalMoney)) + '元'
                    }
                },
                {
                    field: 'totalCgl',
                    title: '成功率',
                    formatter: function (value, row, index) {
                        return  (row.totalCgl == null ? '-' : parseFloat(row.totalCgl)) + '%'
                    }
                },
            ],
        };
        $.table.init(options);
    });
    function changeType(){
        if($("#channelType").val()==""){
            $("#channel").html("<option value=\"\">所有</option>");
            return;
        }
        requrl=ctx+"business/channel/getChannel/"+$("#channelType").val();
        var config = {
            url:requrl ,
            type: "post",
            dataType: "json",
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
                // $.modal.disable();
            },
            success: function(result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    $("#channel").html("<option value=\"\">所有</option>");
                    $.each(result.data, function(key, val) {
                        var option1 = $("<option>").val(val.channel).text(val.channelDesc);
                        $("#channel").append(option1);
                        // form.render('select');
                    });
                }else{
                    $.modal.alertError(result.msg);
                }
            }
        };
        $.ajax(config)
    }
    function getUserSelectTree() {
        //查询条件
        var params = {
            merchantType: "ms"
        };
        var config = {
            url:userTreeurl ,
            type: "post",
            dataType: "json",
            data: params,
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
                // $.modal.disable();
            },
            success: function(result) {
                $.modal.closeLoading();
                $('select[name=recipientUid]').select2ztree({
                    textField : 'name',
                    titleField : 'name',
                    ztree : {
                        setting : $.extend(true, {
                            treeId : 'userId'
                        }, setting),
                        zNodes : result
                    }
                });

            }
        };
        $.ajax(config)
    }
</script>
</body>
</html>
